﻿using QFramework;
using UnityEngine;

namespace HKTools
{
    /// <summary>
    /// 切换 Target 指令
    /// </summary>
    public class CMD_ChangeCamTarget : AbstractCommand
    {
        // 延时切换时间
        float delayTime;

        HK_TargetEnum targetType;
        string targetName;
        float moveSpeed = -1;
        float wheelSpeed = -1;

        // 切换摄像机目标时，是否闪现过去
        bool isFlash = false;
        bool isBlink = false;

        /// <summary>
        /// 根据 目标枚举值 切换
        /// </summary>
        public CMD_ChangeCamTarget(HK_TargetEnum _targetType, bool isFlash = false, bool isBlink = false)
        {
            targetType = _targetType;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        /// <summary>
        /// 根据 目标枚举值 延时切换
        /// </summary>
        public CMD_ChangeCamTarget(float _delayTime, HK_TargetEnum _targetType, bool isFlash = false, bool isBlink = false)
        {
            delayTime = _delayTime;
            targetType = _targetType;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        /// <summary>
        /// 根据 目标名称 切换
        /// </summary>
        public CMD_ChangeCamTarget(string _targetName, bool isFlash = false, bool isBlink = false)
        {
            targetName = _targetName;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        /// <summary>
        /// 根据 目标名称 延时切换
        /// </summary>
        public CMD_ChangeCamTarget(float _delayTime, string _targetName, bool isFlash = false, bool isBlink = false)
        {
            delayTime = _delayTime;
            targetName = _targetName;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        public CMD_ChangeCamTarget(HK_TargetEnum _targetType, float _moveSpeed, bool isFlash = false, bool isBlink = false)
        {
            targetType = _targetType;
            moveSpeed = _moveSpeed;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        public CMD_ChangeCamTarget(float _delayTime, HK_TargetEnum _targetType, float _moveSpeed, bool isFlash = false, bool isBlink = false)
        {
            delayTime = _delayTime;
            targetType = _targetType;
            moveSpeed = _moveSpeed;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        public CMD_ChangeCamTarget(string _targetName, float _moveSpeed, bool isFlash = false, bool isBlink = false)
        {
            targetName = _targetName;
            moveSpeed = _moveSpeed;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        public CMD_ChangeCamTarget(float _delayTime, string _targetName, float _moveSpeed, bool isFlash = false, bool isBlink = false)
        {
            delayTime = _delayTime;
            targetName = _targetName;
            moveSpeed = _moveSpeed;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        public CMD_ChangeCamTarget(HK_TargetEnum _targetType, float _moveSpeed, float _wheelSpeed, bool isFlash = false, bool isBlink = false)
        {
            targetType = _targetType;
            moveSpeed = _moveSpeed;
            wheelSpeed = _wheelSpeed;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        public CMD_ChangeCamTarget(float _delayTime, HK_TargetEnum _targetType, float _moveSpeed, float _wheelSpeed, bool isFlash = false, bool isBlink = false)
        {
            delayTime = _delayTime;
            targetType = _targetType;
            moveSpeed = _moveSpeed;
            wheelSpeed = _wheelSpeed;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        public CMD_ChangeCamTarget(string _targetName, float _moveSpeed, float _wheelSpeed, bool isFlash = false, bool isBlink = false)
        {
            targetName = _targetName;
            moveSpeed = _moveSpeed;
            wheelSpeed = _wheelSpeed;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        public CMD_ChangeCamTarget(float _delayTime, string _targetName, float _moveSpeed, float _wheelSpeed, bool isFlash = false, bool isBlink = false)
        {
            delayTime = _delayTime;
            targetName = _targetName;
            moveSpeed = _moveSpeed;
            wheelSpeed = _wheelSpeed;
            this.isFlash = isFlash;
            this.isBlink = isBlink;
        }

        protected override void OnExecute()
        {
            if (delayTime > 0)
            {
                ActionKit.Delay(delayTime, () =>
                {
                    if (string.IsNullOrEmpty(targetName))
                        this.GetSystem<IHK_TargetCamSystem>().ChangeTargetByEnum(targetType, moveSpeed, wheelSpeed, isFlash, isBlink);
                    else
                        this.GetSystem<IHK_TargetCamSystem>().ChangeTargetByName(targetName, moveSpeed, wheelSpeed, isFlash, isBlink);
                }).StartGlobal();
            }
            else
            {
                if (delayTime < 0)
                {
                    Debug.LogError("相机切换的延时时间不能为负值！");
                }

                if (string.IsNullOrEmpty(targetName))
                    this.GetSystem<IHK_TargetCamSystem>().ChangeTargetByEnum(targetType, moveSpeed, wheelSpeed, isFlash, isBlink);
                else
                    this.GetSystem<IHK_TargetCamSystem>().ChangeTargetByName(targetName, moveSpeed, wheelSpeed, isFlash, isBlink);
            }
        }
    }
}